package com.example.aop.autoproxy.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibCallback implements MethodInterceptor {

    public Object target;

    public CglibCallback(Object target){
        this.target = target;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

        System.out.println("前置通知");

        // 目标对象 -> 直接调用父类方法 -> super.add()
        Object invoke = proxy.invoke(target,args);

        System.out.println("后置通知");

        return invoke;
    }
}
